<?php
/**
 * Created by PhpStorm.
 * User: Abdulaziz
 * Date: 15/7/6
 * Time: 下午12:08
 */


class ReplayAction extends CommonAction
{   //已被答案试图
    public function show()
    {
        import('ORG.Util.Page');
        $count=M('message')->where(array('status'=>1))->count();
        $page=new page($count,10);
        $limit=$page->firstRow.','.$page->listRows;
        $message = M('message')->where(array('status'=>array('eq',1)))->order('id DESC')->limit($limit)->select();
        $this->page=$page->show();
        $this->assign('replay_show', $message)->display();
    }
    /*添加试图
     * */
    public function add()
    {
        $this->display();
    }
    /*
    *只是后台问题查看方法
    *  */
    public function index()
    {
        import('ORG.Util.Page');
        $count=M('message')->where(array('status'=>0))->count();
        $page=new page($count,10);
        $limit=$page->firstRow.','.$page->listRows;
        $message = M('message')->where(array('status'=>array('eq',0)))->order('id desc')->limit($limit)->select();
        $this->page=$page->show();
        $this->assign('message', $message)->display();
    }
    /*
     *只是回复和编辑页面
     *  */
    public function replay()
    {
        if(!IS_GET) halt('页面不存在！');
        $db=M('message')->where(array('id'=>array('eq',I('id'))))->select();
        $this->qustion=$db;
        $this->display();
    }
    /*
    *只是回复和编辑页面方法
    *  */
    public function run_replay()
    {
        if(!IS_POST) halt('页面不存在！');

        $data = array(
            'mes_replay' => I('mes_replay'),
            'ask_content' => I('ask_content'),
            'status'=>1,
            'replayer_ip' => get_client_ip(),
            'replay_time' => date('Y-m-d',time()),
            'replayer_name' => session('username'),

        );
        if(M('message')->where(array('id'=>array('eq',I('id'))))->save($data)){
            $this->success('添加成功',U('show'));
        }else{
           $this->error('添加失败');
        }

    }  /*
    *只是回复和编辑页面方法
    *  */
    public function run_add()
    {
        if(!IS_POST) halt('页面不存在！');
        $data = array(
            'mes_replay' => I('mes_replay'),
            'ask_content' => I('ask_content'),
            'status'=>1,
            'replayer_ip' => get_client_ip(),
            'replay_time' => date('Y-m-d',time()),
            'ask_time' => date('Y-m-d',time()),
            'replayer_name' => session('username'),
        );
        if(M('message')->add($data)){
            $this->success('添加成功',U('show'));
        }else{
           $this->error('添加失败');
        }

    }
    /*
    *只是删除方法
    *  */
    public function delete()
    {
        if(M('message')->where(array('id'=>array('eq',I('id'))))->delete()){
            if($_GET['num']==1){
                $this->success('删除成功',U('show'));
            }elseif($_GET['num']==2){
                $this->success('删除成功',U('index'));

            }else{
                $this->success('删除成功',U('show'));
            }
        }else{
            $this->error('删除失败');
        }
    }
    /*
    *只是查看页面方法
    *  */
    public function ask_show()
    {
        $db=M('message')->where(array('id'=>array('eq',I('id'))))->select();
        $this->ask_show=$db;
        $this->display();
    }
}
?>